<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ page
	import="agentFree2.*, java.net.*,
 java.io.*,
 java.util.*,
 javax.jdo.PersistenceManager,
 java.util.regex.*,
 javax.servlet.http.*"%>
 
<%
request.setCharacterEncoding("UTF-8");
System.out.println(request.getCharacterEncoding());
String submitted = request.getParameter("submitted");

if ("true".equals(submitted)){
	StringReader str = new StringReader(request.getParameter("input"));
	BufferedReader reader = new BufferedReader(str);
	Date date = new Date();
	Long agentPhoneNumber;
	String agentName ="";
	String temp = "";
	String url = "";
	String[] tempArr;
	int count = 0;
	Agent agnt;
	PersistenceManager pm = PMF.get().getPersistenceManager();
	
		while ((temp = reader.readLine())!=null) {
				count++;
				try {
					tempArr = temp.split("       ");
						if (tempArr.length == 4){
							agentPhoneNumber = Long.parseLong(tempArr[0]);
							agentName = tempArr[1];
							url = tempArr[3];
				 			agnt = new Agent(agentName, agentPhoneNumber, date, url);
				 			pm.makePersistent(agnt);
				 			out.println("Successfull record - "+ count + Arrays.toString(tempArr));
						}
						out.println(tempArr.length);
						if (tempArr.length == 2){
							agentPhoneNumber = Long.parseLong(tempArr[0]);
							agentName = tempArr[1];
							System.out.println(agentName);
							url = "manual load";
				 			agnt = new Agent(agentName, agentPhoneNumber, date, url);
				 			pm.makePersistent(agnt);
				 			out.println("Successfull record - "+ count + Arrays.toString(tempArr));
						}
					}catch(Exception e){
						out.print(e);
			}
			
	        }
    	str.close();
    	reader.close();
	    pm.close();
}
%>
<html>
	<head>
	</head>
	<body>
		<form action="send.jsp">
			<textarea rows="40" cols="150" name="input"></textarea>
			<input type="hidden" name="submitted" value="true">
			<button type="submit">Submit</button>
		</form>
	</body>
</html>